package Servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import anonymus.excepcion.DAOExcepcion;
import anonymus.modelo.Cancha;
import anonymus.negocio.CanchaNegocio;

/**
 * Servlet implementation class ListarAlquilerCanchaServlet
 */
@WebServlet("/ListarAlquilerCanchaServlet")
public class ListarAlquilerCanchaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ListarAlquilerCanchaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int local = Integer.parseInt(request.getParameter("cboNombreLocal"));
		System.out.println(local + "local");

				
		String fechaInicio = request.getParameter("txtDiaInicio");
		System.out.println(fechaInicio );
		String fechaFin = request.getParameter("txtDiaFin");
		System.out.println(fechaFin );

		
		CanchaNegocio neg = new CanchaNegocio();
		Collection<Cancha> adm=new ArrayList<Cancha>();
             try {
            	 		adm = neg.buscarAlquilerCanchas(local, fechaInicio, fechaFin);
            	 		
            	 		System.out.print(adm.size());
        				
        				request.setAttribute("Canchitas", adm);
        				RequestDispatcher rd = request.getRequestDispatcher("ListarAlquilerCancha.jsp");
        				rd.forward(request, response);	
                        }
                catch (DAOExcepcion e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
              
	}
}
